package com.yidiandao.business.ui.widget.listview.viewholder;

import android.view.View;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.yidiandao.business.R;
import com.yidiandao.business.data.bean.Goods;
import com.yidiandao.business.ui.widget.listview.ViewHolder;
import com.yidiandao.business.utils.ImageLoader;
import com.yidiandao.business.utils.TextRenderUtils;
import com.yidiandao.business.utils.UIUtils;

/**
 * 换购商品 - 单个商品ViewHolder
 */
public class ChooseGiftSingleHolder extends ViewHolder {

    private RelativeLayout rlytSelect;

    private CheckBox cbSelect;

    private ImageView ivGoodsImage;

    private TextView tvTitle;

    private TextView tvPrice;

    private TextView tvCount;

    @Override
    protected void initView(View rootView) {
        rlytSelect = (RelativeLayout) rootView.findViewById(R.id.rlyt_select);
        cbSelect = (CheckBox) rootView.findViewById(R.id.cb_select);
        ivGoodsImage = (ImageView) rootView.findViewById(R.id.iv_goods_image);
        tvTitle = (TextView) rootView.findViewById(R.id.tv_title);
        tvPrice = (TextView) rootView.findViewById(R.id.tv_price);
        tvCount = (TextView) rootView.findViewById(R.id.tv_count);
    }

    @Override
    protected int getItemLayoutId() {
        return R.layout.item_choose_single_gift;
    }

    public void refreshUI(Goods goods) {
        tvTitle.setText(goods.getGoodsName());
        tvPrice.setText(
                TextRenderUtils.getBeautyPrice(
                        goods.getGoodsPrice() + "", null, UIUtils.dp2px(16), UIUtils.dp2px(13)));
        ImageLoader.loadImageWithPlaceHolder(mContext, ivGoodsImage, goods.getGoodsThumb());
        tvCount.setText(UIUtils.getString(R.string.goods_count, goods.getGoodsNumber()));

        // 根据赠品是否选择来 确定 是否选中当前的赠品
        cbSelect.setChecked(goods.isSelected());
    }
}
